{extend name="common/public"/}
{block name="content"}
<div class="am-g">
	<div class="am-u-sm-12">
		<div class="admin-bar"><a class="am-btn am-btn-primary am-radius am-btn-xs" href="{:url('index')}">备份数据</a></div>
		
		<table class="am-table admin-table">
			<thead>
				<tr>
				<th width="200">备份名称</th>
				<th width="80">卷数</th>
				<th width="80">压缩</th>
				<th width="80">数据大小</th>
				<th width="200">备份时间</th>
				<th>状态</th>
				<th width="120">操作</th>
				</tr>
			</thead>
			<tbody>
				{volist name="list" id="data"}
				<tr>
				<td>{$data.time|date='Ymd-His'}</td>
				<td>{$data.part}</td>
				<td>{$data.compress}</td>
				<td>{$data.size|format_bytes}</td>
				<td>{$key}</td>
				<td>-</td>
				<td class="action">
					<a class="db-import" href="{:url('import?time='.$data['time'])}">还原</a>&nbsp;
					<a class="ajax-get" href="{:url('del?time='.$data['time'])}">删除</a>
				</td>
				</tr>
				{/volist}
			</tbody>
		</table>
	</div>
</div>
{/block}

{block name="js"}
<script type="text/javascript" src="/static/js/layer/layer.js"></script>
<script type="text/javascript">
$(".db-import").click(function(){
	var self = this, code = ".";
	$.get(self.href, success, "json");
	window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
	return false;

	function success(data){
		if(data.code){
			if(data.data.gz){
				data.msg += code;
				if(code.length === 5){
					code = ".";
				}else{
					code += ".";
				}
			}
			$(self).parent().prev().text(data.msg);
			if(data.data.part){
				$.get(self.href, 
					{"part" : data.data.part, "start" : data.data.start}, 
					success, 
					"json"
				);
			}else{
				window.onbeforeunload = function(){ return null; }
			}
		}else{
			layer.msg(data.msg);
		}
	}
});

$(".ajax-get").click(function(){
	var self = this;
	layer.confirm("确认删除？", function(){
		$.get(self.href, function(data){
			if(data.code){
				layer.msg(data.msg, function(){history.go(0);});
			}else{
				layer.msg(data.msg);
			}
		}, "json");
	});
	return false;
});
</script>
{/block}